'use strict';
(function(w){
	w.confirm = function(msg,fn){
		if(typeof msg == 'function') fn = msg ;
		msg = (fn != msg && msg) || '您确认执行该操作吗?';

		if(!$('.modalx')[0]) initx();
		$('.panelc .content').html(msg);	
		$('.modalx , .panelc').fadeIn(500);
		$('.confirmc').off('click').on('click',function(){
			fn();
		})
	};
	w.alert = function(msg){
		msg = msg || '自定义信息!';
		if(!$('.modalx')[0]) initx();
		$('.panela .content').html(msg);	
		$('.modalx , .panela').fadeIn(500);
	};
	w.alertBig = function(msg){
		msg = msg || '工作内容未填写!';
		if(!$('.modalx')[0]) initx();
		$('.bigPanela .content').html(msg);	
		$('.modalx , .bigPanela').fadeIn(500);
	};
	w.cancel = function(){
		$('.modalx,.panelx').fadeOut(500);
	};
	function initx(){
		var modal = '<div class="modalx" style="position:absolute;top:0;\
			left:0;width:100%;height:100%;background-color:#000;opacity:0.4;z-index:100;"></div>';
		var panelc  = '<div class="panelx panelc" style="position:absolute;width:250px;height:150px;z-index:100;top:50%;left:50%;margin-top:-75px;\
						margin-left:-125px;background-color:#fff;border-radius:5px;overflow:hidden;font-size:14px;display:none;">\
							<div class="title" style="background-color: #e6e6e6;height: 36px;line-height: 36px;padding-left:13px;color:#777;">信息</div>\
							<div class="content" style="font-size: 15px;width: max-content;margin: 26px auto auto 20px;">您确认要执行该操作吗?</div>\
							<div class="btns" style="position: absolute;bottom: 12px;right: 24px;">\
								<span onclick="cancel();" style="display: inline-block;background-color: #ddd;\
					    					 padding: 4px 10px;border-radius: 2px;color: #777;margin-right: 6px;">取消</span>\
								<span class="confirmc" style="display: inline-block;background-color: #34a3ff;\
					   				 		padding: 4px 10px;border-radius: 2px;color: #fff;">确认</span>\
							</div>\
						</div>';
		var panela  = '<div class="panelx panela indexa" style="position:absolute;width:250px;height:150px;z-index:110;top:50%;left:50%;margin-top:-75px;\
						margin-left:-125px;background-color:#fff;border-radius:5px;overflow:hidden;font-size:14px;display:none;">\
							<div class="title" style="background-color: #e6e6e6;height: 36px;line-height: 36px;padding-left:13px;color:#777;">提示</div>\
							<div class="content contenta" style="font-size: 15px;width: max-content;margin: 26px auto auto 20px;">自定义消息!</div>\
							<div class="btns" style="position: absolute;bottom: 12px;right: 24px;">\
								<span onclick="cancel();" style="display: inline-block;background-color: #34a3ff;\
					   				 		padding: 4px 10px;border-radius: 2px;color: #fff;">确认</span>\
							</div>\
						</div>';
		var bigPanela  = '<div class="panelx bigPanela" style="position:absolute;width:80%;height:40%;z-index:110;top:30%;left:10%;\
			background-color:#fff;border-radius:5px;overflow:hidden;font-size:14px;display:none;">\
			<div class="title" style="background-color: #e6e6e6;height: 36px;line-height: 36px;padding-left:13px;color:#777;">工作职责</div>\
			<div class="content contenta" style="font-size: 15px;overflow-y: auto;height: 60%;text-indent: 25px;margin: 2px;">自定义消息!</div>\
			<div class="btns" style="position: absolute;bottom: 12px;right: 24px;">\
			<span onclick="cancel();" style="display: inline-block;background-color: #34a3ff;\
			padding: 4px 10px;border-radius: 2px;color: #fff;">确认</span>\
			</div>\
			</div>';
		$('html,body').css('height','100%');
		$('body').append( modal + panelc + panela + bigPanela );
	}
})(window);

String.prototype.format = function(args) {
	var result = this;
	if (arguments.length < 1) {
		return this;
	}
	var data = arguments;
	if (arguments.length == 1 && typeof (args) == 'object') {
		data = args;
	}
	for ( var key in data) {
		var value = data[key];
		if (value == undefined) {
			value = '';
		}
		result = result.replaceAll("\\{" + key + "\\}", value);
	}
	return result;
}

String.prototype.replaceAll = function(exp, newStr) {
	return this.replace(new RegExp(exp, "gm"), newStr);
};

